<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入VUE-->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>欢迎来到 {{ name }}</h2>
        <h2>student.age = {{ student.name }}</h2>
        <h2>student.age = {{ student.age }}</h2>
        <h2 v-if="student.key">key = {{ student.key }}</h2>
        <button @click='addProperty'>点我num1 ++</button>
    </div>
</body>
<script>
    Vue.config.productionTip = false

    const vm = new Vue({
        el: '#root',
        data: {
            name: '尚硅谷',
            numbers: {
                num1: 1,
                num2: 2
            },
            student: {
                name: '张三',
                age: 18,
            }
        },
        methods: {
            addProperty() {
                console.log('==========');
                this.$set(this.student, 'key', 'value')
            }
        },
    })
</script>

</html>